﻿using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using BlueHarvestSnippetGenerator.Snippets.SnippetModel;

namespace BlueHarvestSnippetGenerator.Snippets.SnippetControl
{
    public class CodeSampleInterpreter
    {

        private const string REPLACEMENT_SYMBOL_VS = "$";
        //private const string END_SYMBOL_JAVA = "}";
        private const string END_ANCHOR_VS = "$end$";
        //private const string END_ANCHOR_JAVA = "${cursor}";

        /// <summary>
        /// 
        /// </summary>
        /// <param name="snippetDetail"></param>
        /// <returns></returns>
        public string InterpreteSnippetTemplate(SnippetDetail snippetDetail)
        {
            if (snippetDetail == null)
                return null;

            string resolvedSnippetCode = snippetDetail.SnippetTemplate;


            if (snippetDetail.VariableDeclarations != null)
            {
                foreach (var variableDeclaration in snippetDetail.VariableDeclarations)
                {
                    var dval = variableDeclaration.DefaultValue ?? variableDeclaration.FunctionValue;

                    resolvedSnippetCode = resolvedSnippetCode.Replace(REPLACEMENT_SYMBOL_VS + variableDeclaration.Id + REPLACEMENT_SYMBOL_VS, dval);
                }
            }

            return resolvedSnippetCode.Replace(END_ANCHOR_VS, "");
     
        }

        
    }
}
